package com.haiyu.manager.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.haiyu.manager.dao.UserAddressInfoMapper;
import com.haiyu.manager.pojo.UserAddressInfo;
import com.haiyu.manager.response.PageDataResult;
import com.haiyu.manager.service.AddressInfoService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AddressInfoServiceImpl implements AddressInfoService {
    @Autowired
    UserAddressInfoMapper userAddressInfoMapper;
    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Override
    public PageDataResult getUserAddressInfo(String buyerOpenid, Integer pageNum, Integer pageSize) {
        PageDataResult pageDataResult = new PageDataResult();
        List<UserAddressInfo>userAddressInfos = userAddressInfoMapper.getUserAddressInfo(buyerOpenid);

        System.out.println("userAddressInfos有" + userAddressInfos);
        PageHelper.startPage(pageNum, pageSize);

        if (userAddressInfos.size() != 0) {
            PageInfo<UserAddressInfo> pageInfo = new PageInfo<>(userAddressInfos);
            pageDataResult.setList(userAddressInfos);
            pageDataResult.setTotals((int) pageInfo.getTotal());
        }
        return pageDataResult;
    }

    //@Override
    /*public List<UserAddressInfo> getUserAddressInfo(String buyerOpenid) {
        return addressInfoService.getUserAddressInfo(buyerOpenid);
    }*/
}
